

#### Alternate Windows #### 
m1 <- lm_robust(soc.cl_bin ~ trial, 
                data = subset(lapop12, trend < 7 & trend > -7 & trend != 0 ),
                fixed_effects = estratopri + estratosec, 
                se_type = 'stata')
m2 <-lm_robust(soc.cl_bin ~ trial, data = subset(lapop12, trend < 6 & trend > -6 & trend != 0 ),
               fixed_effects =  estratopri + estratosec, 
               se_type = 'stata')
m3 <-lm_robust(soc.cl_bin ~ trial, data = subset(lapop12, trend < 5 & trend > -5 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m4 <-lm_robust(soc.cl_bin ~ trial, data = subset(lapop12, trend < 4 & trend > -4 & trend != 0 ),
               fixed_effects =  estratopri + estratosec, 
               se_type = 'stata')
m5 <-lm_robust(soc.cl_bin ~ trial, data = subset(lapop12, trend < 3 & trend > -3 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m6 <-lm_robust(soc.cl_bin ~ trial, data = subset(lapop12, trend < 2 & trend > -2 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')

coef.name <- c('6 Days', '5 Days', '4 Days', '3 Days', '2 Days', '1 Days')
y <- c(summary(m1)$coefficients[,1], summary(m2)$coefficients[,1],
       summary(m3)$coefficients[,1], summary(m4)$coefficients[,1],
       summary(m5)$coefficients[,1], summary(m6)$coefficients[,1])  
U <- c(summary(m1)$coefficients[,6], summary(m2)$coefficients[,6], 
       summary(m3)$coefficients[,6], summary(m4)$coefficients[,6], 
       summary(m5)$coefficients[,6], summary(m6)$coefficients[,6])  
L <- c(summary(m1)$coefficients[,5], summary(m2)$coefficients[,5],  
       summary(m3)$coefficients[,5], summary(m4)$coefficients[,5],
       summary(m5)$coefficients[,5], summary(m6)$coefficients[,5])  
plot.df <- data.frame(coef.name, y, U, L)


p1 <- ggplot(plot.df, aes(x = coef.name, y = y)) +
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = U, ymin = L), width=.1,
                position=position_dodge(.9)) + 
  geom_hline(yintercept = 0) + 
  ggtitle("Social Cleansing") + 
  xlab("Treatment Window") +
  ylab("Partial Derivative") +
  theme_bw()


m1 <- lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 7 & trend > -7 & trend != 0 ),
                fixed_effects = estratopri + estratosec, 
                se_type = 'stata')
m2 <-lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 6 & trend > -6 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m3 <-lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 5 & trend > -5 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m4 <-lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 4 & trend > -4 & trend != 0 ),
               fixed_effects =  estratopri + estratosec, 
               se_type = 'stata')
m5 <-lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 3 & trend > -3 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m6 <-lm_robust(torture_bin ~ trial, data = subset(lapop12, trend < 2 & trend > -2 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')

coef.name <- c('6 Days', '5 Days', '4 Days', '3 Days', '2 Days', '1 Days')
y <- c(summary(m1)$coefficients[,1], summary(m2)$coefficients[,1],
       summary(m3)$coefficients[,1], summary(m4)$coefficients[,1],
       summary(m5)$coefficients[,1], summary(m6)$coefficients[,1])  
U <- c(summary(m1)$coefficients[,6], summary(m2)$coefficients[,6], 
       summary(m3)$coefficients[,6], summary(m4)$coefficients[,6], 
       summary(m5)$coefficients[,6], summary(m6)$coefficients[,6])  
L <- c(summary(m1)$coefficients[,5], summary(m2)$coefficients[,5],  
       summary(m3)$coefficients[,5], summary(m4)$coefficients[,5],
       summary(m5)$coefficients[,5], summary(m6)$coefficients[,5])  
plot.df <- data.frame(coef.name, y, U, L)


p2 <- ggplot(plot.df, aes(x = coef.name, y = y)) +
  geom_point(size = 2) +
  geom_errorbar(aes(ymax = U, ymin = L), width=.1,
                position=position_dodge(.9)) + 
  geom_hline(yintercept = 0) + 
  ggtitle("Torture") + 
  xlab("Treatment Window") +
  ylab("Partial Derivative") +
  theme_bw()


m1 <- lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 7 | trend > -7 & trend != 0 ),
                fixed_effects = estratopri + estratosec, 
                se_type = 'stata')
m2 <-lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 6 & trend > -6 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m3 <-lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 5 & trend > -5 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m4 <-lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 4 & trend > -4 & trend != 0 ),
               fixed_effects =  estratopri + estratosec, 
               se_type = 'stata')
m5 <-lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 3 & trend > -3 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')
m6 <-lm_robust(fair_trial ~ trial, data = subset(lapop12, trend < 2 & trend > -2 & trend != 0 ),
               fixed_effects = estratopri + estratosec, 
               se_type = 'stata')


coef.name <- c('6 Days', '5 Days', '4 Days', '3 Days', '2 Days', '1 Days')
y <- c(summary(m1)$coefficients[,1], summary(m2)$coefficients[,1],
       summary(m3)$coefficients[,1], summary(m4)$coefficients[,1],
       summary(m5)$coefficients[,1], summary(m6)$coefficients[,1])  
U <- c(summary(m1)$coefficients[,6], summary(m2)$coefficients[,6], 
       summary(m3)$coefficients[,6], summary(m4)$coefficients[,6], 
       summary(m5)$coefficients[,6], summary(m6)$coefficients[,6])  
L <- c(summary(m1)$coefficients[,5], summary(m2)$coefficients[,5],  
       summary(m3)$coefficients[,5], summary(m4)$coefficients[,5],
       summary(m5)$coefficients[,5], summary(m6)$coefficients[,5])  
plot.df <- data.frame(coef.name, y, U, L)


p3 <- ggplot(plot.df, aes(x = coef.name, y = y)) +
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = U, ymin = L), width=.1,
                position=position_dodge(.9)) + 
  geom_hline(yintercept = 0) + 
  ggtitle("Fair Trial") + 
  xlab("Treatment Window") +
  ylab("Partial Derivative") +
  theme_bw()


alt_treatment_window  = cowplot::plot_grid(p1, p2, p3, nrow = 2, labels = 'AUTO')
ggsave('fig-out/alt_treatment_window.pdf', height = 5)
ggsave('fig-out/alt_treatment_window.png', height = 5, dpi = 600)
